package com.scsj.supermarket.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.scsj.supermarket.R;
import com.scsj.supermarket.bean.MineOrderDetailBean;
import com.scsj.supermarket.bean.TotalOrderBean;
import com.scsj.supermarket.view.activity.ordermodel.OrderDetailActivity;

import java.util.List;

/**
 * 订单详情
 */

public class MineOrderDetailAdapter extends BaseQuickAdapter<MineOrderDetailBean.DataBean.ShopOrderGoodsDetailsListBean, BaseViewHolder> {

    private List<MineOrderDetailBean.DataBean.ShopOrderGoodsDetailsListBean> orderItemList;
    private Context mContext;

    public MineOrderDetailAdapter(@Nullable List<MineOrderDetailBean.DataBean.ShopOrderGoodsDetailsListBean> data, Context context) {

        super(R.layout.mine_order_detail_item, data);
        this.orderItemList= data;
        this.mContext=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, MineOrderDetailBean.DataBean.ShopOrderGoodsDetailsListBean item) {

        for (int i=0;i<orderItemList.size();i++){

            //名字
            String goodsName= orderItemList.get(i).getGoodsName();
            TextView goodsNameTv= helper.getView(R.id.order_detail_item_name_tv);
            goodsNameTv.setText(goodsName);

            //商品单价
            double goodsPrice= orderItemList.get(i).getGoodsPrice();
            TextView goodsPriceTv= helper.getView(R.id.order_detail_item_price_tv);
            goodsPriceTv.setText("￥"+goodsPrice);

            //商品数量
            int buyNum= orderItemList.get(i).getBuyNum();
            TextView buyNumTv= helper.getView(R.id.order_detail_item_num_tv);
            buyNumTv.setText("x"+buyNum);

            //商品总价
            double goodsTotalPrice= orderItemList.get(i).getTotalPrice();
            TextView goodsTotalPriceTv= helper.getView(R.id.order_detail_item_total_price_tv);
            goodsTotalPriceTv.setText("￥"+goodsTotalPrice);

            //商品logo
            String goodsUrl= String.valueOf(orderItemList.get(i).getGoodsImage());
            ImageView goodsImgIv= helper.getView(R.id.orderGoodIv);
            Glide.with(mContext).
                    load(goodsUrl).
                    diskCacheStrategy(DiskCacheStrategy.RESULT).
                    thumbnail(0.5f).
                    placeholder(R.drawable.ic_launcher_background).
                    priority(Priority.LOW).
                    error(R.drawable.ic_launcher_background).
                    fallback(R.drawable.ic_launcher_background).
                    into(goodsImgIv);
        }
    }
}
